home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindlink.net!news
- From: Allan_Nienhuis@mindlink.bc.ca (Allan Nienhuis)
- Newsgroups: comp.lang.c++
- Subject: Re: Dynamically allocating 2-dim arrays
- Date: Sun, 07 Apr 1996 13:17:46 GMT
- Organization: MIND LINK! - British Columbia, Canada
- Message-ID: <4k8f3t$ium@fountain.mindlink.net>
- References: <4k47ii$ppa@galaxy.ucr.edu>
- NNTP-Posting-Host: line007.abb.mindlink.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- csamaras@ucrengr.ucr.edu (Constantine Samares) wrote:
-
- > Does anyone out there know the "correct" way of dynamically allocating a
- >2-dimensional array in C++? This is the problem I'm running into:
-
- As far as I know, it can't be done without using a custom class.
-
- Why don't you just use pointer arithmetic instead? it's generally
- much faster, anyways.
-
- eg:
-
- int *PtrTo_int_array;
- int size_of_x_dimension = 100;
- int size_of_y_dimension = 500;
-
- PtrTo_int_array = new int[size_of_x_dimension * size_of_y_dimension];
-
- // access the element like this:
- int x = 50;
- int y = 75;
-
- int element = *(PtrTo_int_array + (x * size_of_y_dimension) + y);
-
-
-
- Or something like that.... :)
-
-
-